#define _CRT_SECURE_NO_WARNINGS
#include"Date.h"
Date::Date(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}
void Date::print()
{
	cout << _year << "/" << _month << "/" << _day << endl;
}
Date& Date::operator+=(int day)
{
	if (day <0)
	{
		return *this -= (-day);
	}
	_day += day;
	while(_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		_month++;
		if (_month == 13)
		{
			_month = 1;
			_year++;
		}
	}
	return *this;
}
Date Date::operator+(int day)
{
	Date time = *this;
	time += day;
	return time;
}
Date Date::operator-(int day)
{
	if (day < 0)
	{
		return *this += (-day);
	}
	Date time = *this;
	time._day -= day;
	while (time._day <= 0)
	{
		time._month--;
		if (time._month == 0)
		{
			time._month = 12;
			time._year--;
		}
		time._day += GetMonthDay(time._year, time._month);
	}
	return time;
}
Date& Date::operator-=(int day)
{
	*this = *this - day;
	return *this;
}
bool Date::operator<(const Date& d)
{
	if (_year < d._day)
	{
		return true;
	}
	else if(_year == d._day)
	{
		if (_month < d._month)
		{
			return true;
		}
		else if(_month == d._month)
		{
			
				return _day < d._day;
		}
	} 
	return false;
}
bool Date::operator==(const Date& d)
{
	return _year == d._year &&
		_month == d._month
		&& _day == d._day;
}
bool Date::operator<=(const Date& d)
{
	return *this < d || *this == d;
}
bool Date::operator>(const Date& d)
{
	return !(*this <= d);
}
bool Date::operator>=(const Date& d)
{
	return !(*this < d);
}
bool Date::operator!=(const Date& d)
{
	return !(*this == d);
}
Date Date::operator++(int)
{
	Date time = *this;
	*this +=  1;
	return time;
}
Date& Date::operator++()
{
	*this +=1;
	return *this;
}
Date Date::operator--(int)
{
	Date time = *this;
	*this -= 1;
	return time;
}
Date& Date::operator--()
{
	*this -= 1;
	return *this;
}